package com.ruoyi.web.controller.wms;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsRepairSummary;
import com.ruoyi.wms.service.IWmsRepairSummaryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报修汇总Controller
 * 
 * @author ruoyi
 * @date 2024-02-15
 */
@Controller
@RequestMapping("/wms/repair")
public class WmsRepairSummaryController extends BaseController
{
    private String prefix = "wms/repair";

    @Autowired
    private IWmsRepairSummaryService wmsRepairSummaryService;

    @RequiresPermissions("wms:repair:view")
    @GetMapping()
    public String repair()
    {
        return prefix + "/repair";
    }

    /**
     * 查询报修汇总列表
     */
    @RequiresPermissions("wms:repair:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsRepairSummary wmsRepairSummary)
    {
        startPage();
        if(!ShiroUtils.getSysUser().isAdmin()){
            wmsRepairSummary.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        List<WmsRepairSummary> list = wmsRepairSummaryService.selectWmsRepairSummaryList(wmsRepairSummary);
        return getDataTable(list);
    }

    /**
     * 导出报修汇总列表
     */
    @RequiresPermissions("wms:repair:export")
    @Log(title = "报修汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsRepairSummary wmsRepairSummary)
    {
        List<WmsRepairSummary> list = wmsRepairSummaryService.selectWmsRepairSummaryList(wmsRepairSummary);
        ExcelUtil<WmsRepairSummary> util = new ExcelUtil<WmsRepairSummary>(WmsRepairSummary.class);
        return util.exportExcel(list, "报修汇总数据");
    }

    /**
     * 新增报修汇总
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报修汇总
     */
    @RequiresPermissions("wms:repair:add")
    @Log(title = "报修汇总", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsRepairSummary wmsRepairSummary)
    {
        return toAjax(wmsRepairSummaryService.insertWmsRepairSummary(wmsRepairSummary));
    }

    /**
     * 修改报修汇总
     */
    @RequiresPermissions("wms:repair:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WmsRepairSummary wmsRepairSummary = wmsRepairSummaryService.selectWmsRepairSummaryById(id);
        mmap.put("wmsRepairSummary", wmsRepairSummary);
        return prefix + "/edit";
    }

    /**
     * 修改保存报修汇总
     */
    @RequiresPermissions("wms:repair:edit")
    @Log(title = "报修汇总", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsRepairSummary wmsRepairSummary)
    {
        return toAjax(wmsRepairSummaryService.updateWmsRepairSummary(wmsRepairSummary));
    }

    /**
     * 删除报修汇总
     */
    @RequiresPermissions("wms:repair:remove")
    @Log(title = "报修汇总", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsRepairSummaryService.deleteWmsRepairSummaryByIds(ids));
    }
}
